﻿using System;
using FunctionalCLR.Core;

namespace FunctionalCLR.Shell.MathematicaInterface {
    public class MMEvaluateNode : ContextFuncNode {

        public MMEvaluateNode() :
            base() {
            base.Value = "mmEvaluate";
        }

        public override object Evaluate() {
            if (Parameters.Count < 1) {
                throw new ArgumentException(
                    "usage: mmEvaluate(expr);");
            }

            Node root = Parameters[0];
            MathematicaExpressionVisitor visitor 
                = new MathematicaExpressionVisitor("", root);
            string ex = visitor.ConvertExpression();
            object result = MathematicaKernel.Instance.Evaluate(ex);

            return result;
        }
    }
}
